package com.walker.kuyun.ui.activity

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.walker.kuyun.databinding.ActivityTestPlayBinding

/**
 * @author 12892
 */
class TestPlayActivity : AppCompatActivity() {
    private lateinit var mBinding: ActivityTestPlayBinding
    private lateinit var webView: WebView
    val TAG = "TestPlay"

    class UrlJs {
        @JavascriptInterface
        fun getContent() {

        }
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityTestPlayBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        webView = mBinding.root
        webView.loadUrl("https://www.369hyt.com:65/share/jHOLWzYvDdAKx48g")
        webView.settings.apply {
            javaScriptEnabled = true
        }


        webView.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                view!!.loadUrl(url!!)
                return true
            }

            override fun onPageFinished(view: WebView?, url: String?) {
                Log.d(TAG, "onPageFinished: $url")
                webView.evaluateJavascript("originalText") {
                    Log.d(TAG, "onCreate: $it")
                }
                webView.evaluateJavascript("let res = eval(originalText);[redirecturl,playlist[0][\"url\"],mp4]") {
                    Log.d(TAG, "onCreate: $it")
                }
            }
        }
    }
}